__author__ = 'toni'

from django.contrib.syndication.views import Feed
from django.shortcuts import get_object_or_404
from django.utils.feedgenerator import Rss201rev2Feed

from models import *

class EventFeed(Feed):
    feed_type = Rss201rev2Feed
    title = "Event RSS"
    link = "/"
    description = "Personal Event RSS!"

    def get_object(self, request, user_name,user_id):
        return get_object_or_404(User, id = user_id, username = user_name)

    def items(self, obj):
        return Event.objects.all().filter(user=obj).order_by('ev_startdate','ev_enddate','ev_starttime','ev_endtime','ev_name')

    def item_title(self, item):
        return item.ev_name

    def item_description(self, item):
        startdate = str(item.ev_startdate.day)+'.'+str(item.ev_startdate.month)+'.'+str(item.ev_startdate.year)
        enddate = str(item.ev_enddate.day)+'.'+str(item.ev_enddate.month)+'.'+str(item.ev_enddate.year)
        starttime = str(item.ev_starttime.hour)+':'+str(item.ev_starttime.minute)
        endtime = str(item.ev_endtime.hour)+':'+str(item.ev_endtime.minute)
        return 'Date: '+startdate + ' - ' + enddate + '<br>Time: ' + starttime + ' - ' + endtime + '<h4>' + item.ev_description+'</h4>'

    def item_link(self, item):
        return "/account/events"


